package com.dailyblue.java.spring.boot.redis.controller;

import lombok.extern.slf4j.Slf4j;
import org.springframework.data.redis.core.StringRedisTemplate;
import org.springframework.data.redis.core.ZSetOperations;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import java.util.Set;

@RestController
@RequestMapping("/zset")
@Slf4j
public class ZSetRedisController {
    @Resource
    private StringRedisTemplate stringRedisTemplate;

    @GetMapping
    public void execute() {
        ZSetOperations operations = stringRedisTemplate.opsForZSet();
        operations.add("A", "abc", 1);
        operations.add("A", "98", 0.4);
        operations.add("A", "你好", 3.71);
        operations.add("A", "bba", 5.7);
        operations.add("A", "88", 0.4);
        operations.add("A", "098", 1.9);
        operations.add("A", "abc", 1.2);
        operations.add("A", "oi", 5.4);
        operations.add("A", "6754", 3.21);
        Set set1 = operations.range("A", 0, -1);
        log.info("set1:{}", set1);
        operations.remove("A", "abc", "98");
        long index1 = operations.rank("A", "oi");
        log.info("index1:{}", index1);


    }
}
